package com.risk.ctrl.credit.service.impl;

import com.alibaba.fastjson.TypeReference;
import com.risk.ctrl.credit.service.CreditService;
import com.risk.ctrl.entity.base.Result;
import com.risk.ctrl.entity.property.CreditProperty;
import com.risk.ctrl.entity.req.AuthReq;
import com.risk.ctrl.entity.req.CreditQueryH5Req;
import com.risk.ctrl.entity.req.CreditQueryReq;
import com.risk.ctrl.entity.resp.AuthResp;
import com.risk.ctrl.entity.resp.CreditQueryH5Resp;
import com.risk.ctrl.entity.resp.CreditQueryResp;
import com.risk.ctrl.enums.ThirdUrlEnum;
import com.risk.ctrl.utils.OkhttpUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class CreditServiceImpl implements CreditService {
    private final CreditProperty creditProperty;
    @Override
    public Result<AuthResp> auth(AuthReq req) {
        String url = ThirdUrlEnum.AUTH_URL.generateUrl(creditProperty.getBaseUrl());
        return OkhttpUtils.post(url, req, null, null, new TypeReference<Result<AuthResp>>(){});
    }

    @Override
    public Result<CreditQueryResp> query(CreditQueryReq req) {
        String url = ThirdUrlEnum.REPORT_QUERY_URL.generateUrl(creditProperty.getBaseUrl());
        return OkhttpUtils.post(url, req, null, null, new TypeReference<Result<CreditQueryResp>>(){});
    }

    @Override
    public Result<CreditQueryH5Resp> queryH5(CreditQueryH5Req req) {
        String url = ThirdUrlEnum.REPORT_QUERY_H5_URL.generateUrl(creditProperty.getBaseUrl());
        return OkhttpUtils.post(url, req, null, null, new TypeReference<Result<CreditQueryH5Resp>>(){});
    }
}
